// TimeData Comparer - Comparer for sorting TimeData objects by Duration.
// Copyright (C) 2009  Robert N. Tenney
// 
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// 
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
using System;
using System.Collections.Generic;


namespace RTenney.Utility.Timekeeping
{
    /// <summary>
    /// Description of TimeDataDurationComparer.
    /// </summary>
    public class TimeDataDurationComparer : IComparer<TimeData>
    {
        /// <summary>
        /// Compares the Duration of one TimeData object with another TimeData object.
        /// </summary>
        /// <param name="x">First TimeData object.</param>
        /// <param name="y">Second TimeData object.</param>
        /// <returns></returns>
        public int Compare(TimeData x, TimeData y)
        {

            // ...and y is not null, compare the
            // content of the two strings.
            //
            int retval = x.Time.CompareTo(y.Time);

            if (retval != 0)
            {
                // If the strings are not of equal length,
                // the longer string is greater.
                //
                return retval;
            }
            else
            {
                // If the strings are of equal length,
                // sort them with ordinary string comparison.
                //
                return x.Time.CompareTo(y.Time);
            }
        }
    }
}

